/*
 * @Author: wangzz wangzhuang@outlook.com
 * @Date: 2024-05-26 22:13:44
 * @LastEditors: wangzz wangzhuang@outlook.com
 * @LastEditTime: 2024-05-26 22:16:18
 * @FilePath: \screw-utils\lib\Math.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const toChineseNumerals = (amount) => {
	let num = Number(amount) || 0
	let units = [
		// 数据单位顺序，一定是从大到小
		{
			sizeStep: 10000000000000000,
			name: '万兆'
		},
		{
			sizeStep: 1000000000000,
			name: '兆'
		},
		{
			sizeStep: 100000000,
			name: '亿'
		},
		{
			sizeStep: 10000,
			name: '万'
		}
	]
	let unit = units.find((item) => {
		return num > item.sizeStep
	})
	if (!!unit) {
		return Number((num / unit.sizeStep).toFixed(1)) + unit.name
	} else {
		return num.toFixed(0)
	}
}

export default {
    toChineseNumerals
}